<template>
  <a-row class='content'>
    <a-col :xs='1' :sm='1' :md='2' :lg='2' :xl='2'></a-col>
    <a-col :style='{top:top}' :xs='24' :sm='11' :md='10' :lg='10' :xl='10'>
      <div id='tool_btn'>
        <a-row>
          <a-col align='center' :xs='24' :sm='24' :md='24' :lg='24' :xl='24'>
            <a-button type='primary' class='toolbox' v-for='(item,index) in jobManageList' :key='item.cupboardDoor'
                      shape='round'
                      @click='click(item,index)'
                      :id='item.cupboardDoor'>
              {{ item.cabinetName }}
            </a-button>
          </a-col>
        </a-row>
      </div>
    </a-col>
    <a-col :style='{top:top}' :xs='24' :sm='4' :md='10' :lg='10' :xl='10'>
      <div id='job_btn'>
        <a-row>
          <a-col align='center' :xs='24' :sm='12' :md='12' :lg='12' :xl='12'>
            <a-button class='job' @click='applyJob()' v-prevent-re-click='3000' shape='round'>申请作业</a-button>
          </a-col>
          <a-col align='center' :xs='24' :sm='12' :md='12' :lg='12' :xl='12'>
            <a-button class='job' @click='exit()' :loading="endJobLoading" shape='round'>结束作业</a-button>
          </a-col>
        </a-row>
        <a-row>
          <a-col align='center' :xs='24' :sm='12' :md='12' :lg='12' :xl='12'>
            <a-button class='job' @click='replaceTool()' shape='round'>更换工具</a-button>
          </a-col>
          <a-col align='center' :xs='24' :sm='12' :md='12' :lg='12' :xl='12'>
            <a-button class='job' @click='exitReplaceTool()' shape='round'>结束更换工具</a-button>
          </a-col>
        </a-row>
        <a-row>
          <a-col align='center' :xs='24' :sm='4' :md='12' :lg='12' :xl='12'>

            <a-button class='job' shape='round' @click='autoInspect' id='inspection' :loading='inspectionLoading'
                      :disabled='disabled'>自动检测
            </a-button>

          </a-col>

          <a-col align='center' :xs='24' :sm='4' :md='12' :lg='12' :xl='12'>
            <a-button class='job' shape='round' @click='inspection' id='jsjc' :disabled='endXJDisabled' :loading="endXJLoading">结束检测</a-button>
          </a-col>
        </a-row>
        <a-row>
          <a-col align='center' :xs='24' :sm='4' :md='12' :lg='12' :xl='12'>
            <a-button class='job' shape='round' @click='openAllDoor' :loading='openAllDoorLoad' id='all'
                      :disabled='disabled'>一键开锁
            </a-button>
          </a-col>
          <a-col align='center' :xs='24' :sm='4' :md='12' :lg='12' :xl='12'>
            <a-button class='sdjob' shape='round' @click='initTool' id="sdcsh">手动初始化</a-button>
          </a-col>
          <a-col align='center' :xs='24' :sm='12' :md='12' :lg='12' :xl='12'>
            <a-button style='width: 80%;height:50px;margin: 10px' @click='logout()' shape='round'>退出系统</a-button>
          </a-col>
        </a-row>
      </div>
    </a-col>

    <a-col :xs='1' :sm='1' :md='2' :lg='2' :xl='2'></a-col>
    <a-modal
      title='更换工具'
      v-model='replaceToolDialog'
      :confirm-loading='replaceLoading'>
      <template slot="footer">
        <a-row>
          <a-col :span="18">
            <a-button class="whetherfont" type='primary' @click='replaceToolOk' :loading='replaceLoading'>是</a-button>
          </a-col>
          <a-col :span="6">
            <a-button class="whetherfont" type='danger' @click='()=>replaceToolDialog=false'>否</a-button>
          </a-col>
        </a-row>
      </template>
      {{ replaceToolText }}
    </a-modal>

    <a-modal
      title='结束更换工具'
      v-model='exitReplaceToolDialog'
      :confirm-loading='exitReplaceLoading'>
      <template slot="footer">
        <a-row>
          <a-col :span="18">
            <a-button class="whetherfont" type='primary' @click='exitReplaceToolOk' :loading='exitReplaceLoading'>是</a-button>
          </a-col>
          <a-col :span="6">
            <a-button class="whetherfont" type='danger' @click='()=>exitReplaceToolDialog=false'>否</a-button>
          </a-col>
        </a-row>
      </template>
      {{ exitReplaceToolText }}
    </a-modal>

    <a-modal
      title='结束作业'
      v-model='endJobDialog'
      :confirm-loading='confirmLoading'>
      <template slot='footer'>
        <a-row>
          <a-col :span="18">
            <a-button class="whetherfont" type='primary' @click='uploadData' :loading='confirmLoading'>是</a-button>
          </a-col >
          <a-col :span="6">
<!--            <a-button class="whetherfont" type='danger' @click='noEndJobOk'>否</a-button>-->
            <a-button class="whetherfont" type='danger' @click='()=>endJobDialog=false'>否</a-button>
          </a-col>
        </a-row>
      </template>
      {{ endJobgDialogText }}
    </a-modal>
    <a-modal
      title='工具损坏信息'
      v-model='toolDestroyInfoDialog'
      :maskClosable=false
      :confirm-loading='toolDestroyInfoLoading'
      @ok='saveToolInfo'>
      <template>
        <div>
          <h3>请选择工具损坏项：</h3>
        </div>
        <a-checkbox-group @change="onChange">
          <a-row v-for="(toolInfo,index) in toolDestroyInfos" :key="index">
            <a-checkbox :value="toolInfo.type">
              {{toolInfo.description}}
            </a-checkbox>
          </a-row>
        </a-checkbox-group>
      </template>
    </a-modal>

    <a-modal
      title='申请作业'
      v-model='applyJobDialog'
      :confirm-loading='applyLoading'>
      <template slot='footer'>
        <a-row>
          <a-col :span="18">
            <a-button class="whetherfont" type='primary' @click='applyForJob' :loading='applyLoading'>是</a-button>
          </a-col>
          <a-col :span="6">
            <a-button class="whetherfont" type='danger' @click='()=>applyJobDialog=false'>否</a-button>
          </a-col>
        </a-row>
      </template>
      {{ applyJobgDialogText }}
    </a-modal>

    <a-modal
      :title='addOrSubtractToolTitle'
      v-model='addOrSubtractToolDialog'
      :maskClosable=false
      :confirm-loading='addOrSubtractToolLoading'>
      <template slot='footer'>
        <a-row>
          <a-col :span="18">
            <a-button class="whetherfont" type='primary' @click='addOrSubtractTool' :loading='addOrSubtractToolLoading'>是</a-button>
          </a-col>
          <a-col :span="6">
            <a-button class="whetherfont" type='danger' @click='()=>addOrSubtractToolDialog=false'>否</a-button>
          </a-col>
        </a-row>
      </template>
      {{ addOrSubtractToolDialogText }}
    </a-modal>

    <a-modal
      title='初始化'
      v-model='initDialog'
      :maskClosable=false
      :confirm-loading='initLoading'>
      <template slot='footer'>
        <a-row>
          <a-col :span="18">
            <a-button class="whetherfont" type='primary' @click='initToolboxInfo' :loading='initLoading'>是</a-button>
          </a-col>
          <a-col :span="6">
            <a-button class="whetherfont" type='danger' @click='()=>initDialog=false'>否</a-button>
          </a-col>
        </a-row>
      </template>
      {{ initDialogText }}
    </a-modal>


    <a-modal
      title='一键巡检'
      v-model='inspectionDialog'
      :confirm-loading='inspectionLoading'>
      <template slot='footer'>
        <a-row>
          <!--取消查看-->
          <a-button shape='round' @click='cancelInspect'>取消</a-button>
          <!--D1-->
          <a-button shape='round' @click="inspectionOk('D1')" type='primary'>箱子在位信息</a-button>
        </a-row>
        <a-row style='margin-top: 10px;margin-bottom: 10px'>
          <!--D2-->
          <a-button shape='round' @click="inspectionOk('D2')" type='primary'>手环在位信息</a-button>
          <!--D3-->
          <a-button shape='round' @click="inspectionOk('D3')" type='primary'>蓝牙配对信息</a-button>
          <!--D01-->
          <a-button shape='round' @click="inspectionOk('D01')" type='primary'>箱子设备状态信息</a-button>
          <!--D06-->
          <!--          <a-button shape="round" @click="inspectionOk('D06')" type="primary">箱子关箱记录信息</a-button>-->
        </a-row>
      </template>
      <a-row>
        <a-col :span='18'>
          <div style='display: inline'><h2 style='display: inline'>巡检结果：</h2></div>
        </a-col>
        <a-col :span='6'>
          <!--当D3返回信息存在未配对设备时，显示该按钮-->
          <a-button style='display: inline' :hidden='hide' type='primary' shape='round'
                    @click='matchBlueTooth' :loading='bluetoothLoading' :disabled='disabled'>
            蓝牙重新配对
          </a-button>
        </a-col>
      </a-row>
      <div v-html='datas'></div>
    </a-modal>

    <a-modal
      title='完整性验证'
      v-model='Completeness'
      @ok='uploadData'>
      <div>
        <a-checkbox>箱子损坏</a-checkbox>
        <br>
        <a-checkbox>标签损坏</a-checkbox>
        <br>
        <a-checkbox>工具丢失</a-checkbox>
        <br>
        <a-checkbox>工具借出</a-checkbox>
        <br>
        <a-checkbox>工具损坏</a-checkbox>
        <br>
        <a-checkbox>手环丢失</a-checkbox>
        <br>
        <a-checkbox>手环损坏</a-checkbox>
        <br>
        <a-checkbox>手环故障</a-checkbox>
      </div>
    </a-modal>

    <a-modal
      title='数据上传'
      v-model='dataUploadDialog'
      :maskClosable=false
      :footer="null"
      :closable="false"
      :confirm-loading='dataUploadLoading'>
<!--      <template slot='footer'>
        <a-button class="whetherfont" type='primary' @click='dataUpload' :loading='dataUploadLoading'>是</a-button>
      </template>-->
      {{ dataUploadDialogText }}
    </a-modal>
  </a-row>
</template>

<script>

import { postAction, putAction, getAction } from '@api/manage'
import { mapActions, mapGetters } from 'vuex'
import user from '../../store/modules/user'

export default {
  name: 'Toolbox',
  inject: ['reload'],
  data() {
    return {
      endJobLoading:false,
      dataUploadDialog:false,
      dataUploadLoading:false,
      dataUploadDialogText:'',
      toolDestroyInfos: [
        { type: 1, description: '工具丢失' },
        { type: 2, description: '工具借出' },
        { type: 3, description: '工具损坏' },
        { type: 4, description: '手环损坏' },
        { type: 5, description: '手环故障' }
      ],
      toolDestroyInfoDialog: false,
      toolDestroyInfoLoading: false,
      toolDestroyInfoText: '',
      initToolLoading: false,
      initTitle: '',
      initDialog: false,
      initLoading: false,
      initDialogText: '等待初始化',
      addOrSubtractToolTitle: '',
      addOrSubtractToolDialog: false,
      addOrSubtractToolLoading: false,
      addOrSubtractToolDialogText: '',
      disabled: false,
      Completeness: false,
      CompletenessLoading: false,
      disabledInspect: false,
      inspectionDialog: false,
      inspectionLoading: false,
      inspectionText: '',
      replaceToolDialog: false,
      exitReplaceToolDialog: false,
      replaceToolText: '',
      exitReplaceToolText: '',
      endJobDialog: false,
      endJobgDialogText: '',
      replaceLoading: false,
      exitReplaceLoading: false,
      bluetoothLoading: false,
      confirmLoading: false,
      applyJobDialog: false,
      applyLoading: false,
      applyJobgDialogText: '',
      cabinetName: '',
      toolboxName: '',
      operator: '',
      cupboardDoor: '',
      equipmentNum: '',
      status: '',
      index: '',
      Text: '',
      Text1: '',
      Text2: '',
      Text3: '',
      Text4: '',
      Text5: '',
      datas: '',
      hide: true,
      openAllDoorLoad: false,
      url: {
        add: '/jobmanage/jobManage/add',
        edit: '/jobmanage/jobManage/edit',
        status: '/jobmanage/jobManage/jobManageStatus',
        ctlist: '/cabinetmanage/cabinetManage/getCTList',
        openAllDoor: '/toolboxrest/unlock',
        inspection: '/toolboxrest/automaticInspection',
        replace: '/jobmanage/jobManage/replacementTool',
        exitReplace: '/jobmanage/jobManage/exitReplacementTool',
        bluetooth: '/toolboxrest/setBluetoothName',
        initToolboxInfo: '/toolboxrest/initToolboxInfo',
        endXJ: '/toolboxrest/closeAutomaticInspection',
        uploadData:'/jobmanage/jobManage/uploadData'
      },
      jobManageList: [],
      timer: null,
      type: 0,
      equipmentNums: '',
      bluetoothNames: '',
      rightNavShow: true,
      top: '35%',
      endXJLoading:false,
      endXJDisabled:true,
      dataContent:'数据上传中，请耐心等待...'
    }
  },
  created() {
    this.getCTList()
    this.isMobile()
    /*alert(localStorage.getItem("endXJDisabled"))*/
    let dis = localStorage.getItem("endXJDisabled")
    if(dis!=null){
      this.endXJDisabled = localStorage.getItem("endXJDisabled")
    }
  },
  mounted() {
    this.getLoginPerson()
  },
  methods: {
    ...mapActions(['Logout']),
    ...mapGetters(['userInfo']),
    dataUpload(){
      this.dataUploadDialog = false
      this.addOrSubtractToolDialog = true
      this.addOrSubtractToolDialogText = '是否初始化？'
      this.addOrSubtractToolTitle = '结束作业'
    },
    getCTList() {
      let that = this
      getAction(this.url.ctlist).then(res => {
        let jobs = res.result
        for (let i = 0; i < jobs.length; i++) {
          that.jobManageList.push({
            cupboardDoor: jobs[i].cabinetCode,
            equipmentNum: jobs[i].toolboxNum,
            status: '3',
            toolboxName: jobs[i].toolboxName,
            cabinetName: jobs[i].cabinetName,
            operator: ''
          })
        }
        that.getJobManageStatus()
      })
    },
    getJobManageStatus() {

      let that = this
      let flag = 0
      for (let i = 0; i < that.jobManageList.length; i++) {
        let jobMangage = that.jobManageList[i]
        let params = {
          cupboardDoor: jobMangage.cupboardDoor,
          equipmentNum: jobMangage.equipmentNum
        }
        getAction(that.url.status, params).then(res => {
          if (res.result != null) {
            let job = res.result
            // that.jobManageList[i].operator = job.operator
            that.jobManageList[i].operator = job.operator
            if (job.status === '1') {
              that.jobManageList[i].status = '1'
              document.getElementById(job.cupboardDoor).style.backgroundColor = '#FF0000'
              document.getElementById(job.cupboardDoor).innerText = jobMangage.toolboxName + '作业中:' + job.operator
            } else if (job.status === '2') {
              that.jobManageList[i].status = '2'
              document.getElementById(job.cupboardDoor).style.backgroundColor = '#FF0000'
              document.getElementById(job.cupboardDoor).innerText = jobMangage.toolboxName + '更换工具中:' + job.operator
            } else {
              that.jobManageList[i].status = '3'
              document.getElementById(jobMangage.cupboardDoor).style.backgroundColor = '#00ff80'
              document.getElementById(jobMangage.cupboardDoor).innerText = jobMangage.cabinetName
            }
          }
        })
      }
    },
    click(item, index) {
      this.equipmentNum = item.equipmentNum
      this.cupboardDoor = item.cupboardDoor
      this.status = item.status
      this.cabinetName = item.cabinetName
      this.toolboxName = item.toolboxName
      this.index = index
      this.operator = item.operator
    },
    //申请作业
    applyJob() {
      if (this.equipmentNum === '') {
        this.$message.info('未选择任何工具柜')
      } else {
        let _this = this
        if (_this.status === '1') {
          _this.$message.info(_this.cabinetName + '中的' + _this.toolboxName + '作业中')
        } else if (_this.status === '2') {
          _this.$message.info(_this.cabinetName + '中的' + _this.toolboxName + '更换工具中')
        } else if (_this.status === '3') {
          this.applyJobDialog = true
          this.applyJobgDialogText = '是否申请' + this.cabinetName + '作业'
        } else {
          _this.$message.info('不支持本操作')
        }
      }
    },
    //虚假的保存工具损坏信息，其实只是结束作业
    saveToolInfo() {
      console.log('假装存了一个模糊的工具损坏信息')
      const _this = this
      this.toolDestroyInfoDialog = false
      this.uploadData()
    },
    //增减工具
    addOrSubtractTool() {
      this.addOrSubtractToolDialog = false
      this.initDialog = true
      this.initDialogText = this.cabinetName + '中的' + this.toolboxName + '等待初始化'
    },
    initTool() {
      if (this.cupboardDoor == '') {
        this.$message.info('未选择任何工具柜')
      } else {
        this.initToolboxInfo()
      }
    },
    //初始化
    initToolboxInfo() {
      let _this = this
      _this.initToolLoading = true
      _this.initLoading = true
      let parameter = {
        cupboardDoor: _this.cupboardDoor
      }
      this.initDialogText = this.cabinetName + '中的' + this.toolboxName + '初始化中...'
      setTimeout(() => {
        postAction(_this.url.initToolboxInfo, parameter).then(res => {
          this.initDialogText = this.cabinetName + '中的' + this.toolboxName + '初始化成功！'
          if (res.success) {
            _this.$message.success(res.message)
            /*console.log('status:' + _this.status)*/
            _this.initLoading = false
            _this.initDialog = false
            _this.initToolLoading = false
          } else {
            _this.$message.error(res.message)
            _this.initLoading = false
            _this.initDialog = false
            _this.initToolLoading = false
          }
        }).catch(error => {
          _this.$message.error('系统异常' + error)
        })
        /*if(_this.status == '1'){
          document.getElementById(_this.cupboardDoor).innerText = _this.toolboxName + '作业中:' + _this.operator
        }else if(_this.status == '2'){
          document.getElementById(_this.cupboardDoor).innerText = _this.toolboxName + '更换工具中:' + _this.operator
        }else{
          document.getElementById(_this.cupboardDoor).innerText = _this.cabinetName
        }*/
      }, 1000)
    },
    //申请作业远程请求
    applyForJob() {
      let _this = this
      this.applyLoading = true
      let parameter = {
        cupboardDoor: _this.cupboardDoor,
        equipmentNum: _this.equipmentNum
      }
      /*_this.applyJobDialog = false
      _this.applyLoading = false*/
      // _this.dataUploadDialog = true
      // _this.dataUploadDialogText = '数据上传中，请耐心等待...'
      document.getElementById(_this.cupboardDoor).innerText = '开启中'
      setTimeout(() => {
        postAction(_this.url.add, parameter).then(res => {
          if (res.success) {
            _this.operator = res.result.operator
            _this.jobManageList[_this.index].operator = res.result.operator
            _this.$set(_this.jobManageList[_this.index], 'status', '1')
            _this.status = '1'
            _this.$message.success(_this.cabinetName + '中的' + _this.toolboxName + '作业中')
            document.getElementById(_this.cupboardDoor).style.backgroundColor = '#FF0000'
            document.getElementById(_this.cupboardDoor).innerText = _this.toolboxName + '作业中:' + _this.operator
            _this.applyJobDialog = false
            _this.applyLoading = false
            /*_this.dataUploadDialog = false
            _this.addOrSubtractToolDialog = true*/
            _this.addOrSubtractToolDialogText = '是否增减工具？'
            _this.addOrSubtractToolTitle = '申请作业'
           // _this.dataUploadDialogText = "数据上传完毕！"
            /*setTimeout(()=>{
              _this.dataUploadDialog = false
              _this.addOrSubtractToolDialog = true
              _this.addOrSubtractToolDialogText = '是否增减工具？'
              _this.addOrSubtractToolTitle = '申请作业'
            },3000)*/
          } else {
           //_this.dataUploadDialogText = "数据上传失败，请重试！"
            _this.$message.error(_this.cabinetName + '开锁失败')
            _this.applyJobDialog = false
            _this.applyLoading = false
           /*setTimeout(()=>{
             _this.dataUploadDialog = false
             _this.$message.error(_this.cabinetName + '开锁失败')
           },3000)*/
          }
        }).catch(error => {
          _this.$message.error('系统异常' + error)
        })
      }, 500)
    },
    // 更换工具
    replaceTool() {
      if (this.equipmentNum === '') {
        this.$message.info('未选择任何工具柜')
      } else {
        if (this.status === '1') {
          this.replaceToolText = this.operator + ':是否要更换' + this.cabinetName+'工具'
          this.replaceToolDialog = true
        } else if (this.status === '2') {
          this.$message.warn(this.cabinetName + '中的' + this.toolboxName + '更换工具中')
        } else {
          this.$message.warn(this.cabinetName + '中的' + this.toolboxName + '未参与作业')
        }
      }
    },
    // 更换工具远程请求
    replaceToolOk() {
      this.replaceLoading = true
      let _this = this
      let params = {
        equipmentNum: this.equipmentNum,
        cupboardDoor: this.cupboardDoor,
        userName: this.operator
      }
      setTimeout(() => {
        putAction(this.url.replace, params).then(res => {
          if (res.success) {
            _this.$message.info(_this.cabinetName + '中的' + _this.toolboxName + '更换工具中:' + _this.operator)
            document.getElementById(_this.cupboardDoor).innerText = _this.toolboxName + '更换工具中:' + _this.operator
            _this.jobManageList[_this.index].status = '2'
            _this.status = '2'
            _this.replaceLoading = false
            _this.replaceToolDialog = false
            _this.addOrSubtractToolDialog = true
            _this.addOrSubtractToolDialogText = '是否增减工具？'
            _this.addOrSubtractToolTitle = '申请作业'
          }else{
            _this.$message.info(_this.cabinetName + '中的' + _this.toolboxName + '更换工具失败，请重试')
            this.replaceLoading = false
            this.replaceToolDialog = false
          }
        })
      }, 1000)
    },
    //结束更换工具
    exitReplaceTool() {
      if (this.equipmentNum === '') {
        this.$message.info('未选择任何工具柜')
      } else {
        if (this.status === '2') {
          this.exitReplaceToolText = '是否结束更换工具'
          this.exitReplaceToolDialog = true
        } else {
          this.$message.warn(this.cabinetName + '中的' + this.toolboxName + '未在更换工具')
        }
      }
    },
    //结束作业
    exit() {
      const _this = this
      if (this.equipmentNum === '') {
        this.$message.info('未选择任何工具柜')
      } else {
        let _this = this
        if (_this.status === '1') {
          this.endJobgDialogText = this.cabinetName +'请将工具箱数据线连接，是否上传数据？'
          this.endJobOk()
          // this.$confirm({
          //   title: '提示',
          //   content: '请确认' + this.cabinetName + '中' + this.toolboxName + '工具、手环是否完好',
          //   onOk: () => {
          //     let parameter = {
          //       cupboardDoor: _this.cupboardDoor,
          //       equipmentNum: _this.equipmentNum
          //     }
          //     setTimeout(() => {
          //       putAction(_this.url.edit, parameter).then(res => {
          //         if (res.success) {
          //           _this.$message.success(_this.cabinetName + '中' + _this.toolboxName + '已归还')
          //           document.getElementById(_this.cupboardDoor).innerText = _this.cabinetName
          //           _this.jobManageList[_this.index].status = '3'
          //           document.getElementById(_this.cupboardDoor).removeAttribute('style')
          //         }
          //       })
          //     }, 2000)
          //   },
          //   onCancel: () => {
          //     _this.Completeness = true
          //   },
          //   okText: '是',
          //   cancelText: '否'
          //
          // })

        } else if (_this.status === '2') {
          this.$message.warn(_this.cabinetName + '中' + _this.toolboxName + '正在更换工具中，请先结束更换工具')
        } else {
          this.$message.warn(_this.cabinetName + '中' + _this.toolboxName + '未参与作业')
        }
      }
    },
    //结束更换工具远程请求
    exitReplaceToolOk() {
      let _this = this
      this.exitReplaceLoading = true
      let params = {
        equipmentNum: this.equipmentNum,
        cupboardDoor: this.cupboardDoor,
        userName: this.operator
      }
      setTimeout(() => {
        putAction(this.url.exitReplace, params).then(res => {
          if (res.success) {
            _this.$message.success(_this.cabinetName + '中' + _this.toolboxName + '已结束更换工具')
            document.getElementById(_this.cupboardDoor).innerText = _this.toolboxName + '作业中:' + _this.operator
            _this.jobManageList[_this.index].status = '1'
            _this.status = '1'
            _this.exitReplaceLoading = false
            _this.exitReplaceToolDialog = false
          }else{
            _this.$message.info(_this.cabinetName + '中' + _this.toolboxName + '结束更换工具失败，请重试')
            _this.exitReplaceLoading = false
            _this.exitReplaceToolDialog = false
          }
        })
      }, 1000)
    },
    //结束作业远程请求
    endJobOk() {
      const _this = this
      let parameter = {
        cupboardDoor: this.cupboardDoor,
        equipmentNum: this.equipmentNum
      }
      _this.endJobLoading = true
      setTimeout(() => {
        putAction(this.url.edit, parameter).then(res => {
          if (res.success) {
            _this.$message.success(_this.cabinetName + res.result)
            _this.endJobLoading = false
            _this.endJobDialog = true
          }else{
            _this.$message.info(_this.cabinetName +'打开失败')
            /*_this.dataUploadDialogText = '数据上传失败，请重试！'*/
            _this.endJobLoading = false
          }
        })
      }, 100)
    },
    //数据上传远程接口
    uploadData(){
      let _this = this
      this.endJobDialog = false
      let parameter = {
        cupboardDoor: this.cupboardDoor,
        equipmentNum: this.equipmentNum
      }
      _this.dataUploadDialog = true
      _this.dataUploadDialogText = '数据上传中,请耐心等待...'
      setTimeout(()=>{
        postAction(_this.url.uploadData,parameter).then(res=>{
          if(res.success){
            _this.dataUploadDialogText = res.message
            document.getElementById(_this.cupboardDoor).innerText = _this.cabinetName
            _this.jobManageList[_this.index].status = '3'
            _this.status = '3'
            document.getElementById(_this.cupboardDoor).removeAttribute('style')
            _this.$message.info(_this.cabinetName + '中' + _this.toolboxName + res.message)
            setTimeout(()=>{
              _this.dataUploadDialog = false
              _this.addOrSubtractToolDialog = true
              _this.addOrSubtractToolDialogText = '是否初始化？'
              _this.addOrSubtractToolTitle = '结束作业'
            },10)
          }else{
            _this.dataUploadDialogText = res.message
            _this.$message.info(_this.cabinetName + '中' + _this.toolboxName + res.message)
            setTimeout(()=>{
              _this.dataUploadDialog = false
            },10)
          }
        })
      },100)
    },
    noEndJobOk() {
      this.endJobDialog = false
      this.toolDestroyInfoDialog = true
    },
    //退出系统
    logout() {
      const that = this
      that.Logout({}).then(res => {
        that.$message.success('退出成功,2秒后将退回到首页')
        setTimeout(() => {
          that.$router.push({ path: '/' })
        }, 2000)
      }).catch(error => {
        that.$message.error({
          title: '错误',
          description: error.message
        })
      })
    },
    getLoginPerson() {

      /*console.log('用户角色：'+user.state.userRole)*/
      console.log(111+localStorage.getItem("role"))
      if (localStorage.getItem("role") !== 'admin'&&localStorage.getItem("role") !== 'super') {
        // document.getElementById('all').setAttribute('disabled', true)
        // document.getElementById('inspection').setAttribute('disabled', true)
        // document.getElementById('jsjc').setAttribute('disabled', true)
        document.getElementById('all').style.display = 'none'
        document.getElementById('inspection').style.display = 'none'
        document.getElementById('jsjc').style.display = 'none'
        document.getElementById('sdcsh').style.display = 'none'
      }
    },
    //一键开锁
    openAllDoor() {
      let _this = this
      let flag = 0
      let params = {
        cabinetCode: ''
      }
      this.jobManageList.forEach(item => {

        if (item.status == '3') {
          flag = 1
          params.cabinetCode = params.cabinetCode + item.cupboardDoor + ','
        }
      })
      if (flag == 0) {
        this.$message.info('当前所有柜门均为打开状态')
      } else {
        this.openAllDoorLoad = true
        postAction(this.url.openAllDoor, params).then(res => {
          if (res.success) {
            /*_this.disabled = true*/
            setTimeout(() => {
              _this.openAllDoorLoad = false
              this.$message.success(res.message)
              let arr = res.result.split(',')
              _this.operator = arr[arr.length - 1]
              /*alert(_this.operator)*/
              /*_this.jobManageList.forEach(job=>{
              document.getElementById(job.cupboardDoor).style.backgroundColor = '#FF0000'
              document.getElementById(job.cupboardDoor).innerText = job.toolboxName + '已借出:' + _this.operator
              })*/
            }, 1000)
            this.reload()
          } else {
            _this.openAllDoorLoad = false
            _this.$message.error('开锁失败')
          }
        })
      }
    },
    //开启自动检测
    autoInspect(){
      let _this = this
      _this.disabledInspect = false
      _this.inspectionLoading = true
      getAction(this.url.inspection).then(res => {
        console.log(res)
        if (res) {
          this.$message.success("自动检测开启成功！")
          _this.endXJDisabled = true
          setTimeout(()=>{
            localStorage.setItem("endXJDisabled",false)
            _this.endXJDisabled = false
          },10000)
        }else{
          this.$message.info('自动检测开启失败，请重试！')
        }
        _this.inspectionLoading = false
      })
    },
    //结束检测
    inspection() {
      this.endXJDisabled = false
      this.Text = ''
      this.endXJLoading = true
      getAction(this.url.endXJ).then(res => {
        if (res.D1 !== '' && res.D1 !== undefined) {
          this.Text1 = res.D1
        }
        if (res.D2 !== '' && res.D2 !== undefined) {
          this.Text2 = res.D2
        }
        if (res.D3 !== '' && res.D3 !== undefined) {
          this.Text3 = res.D3
        }
        if (res.D01 !== '' && res.D01 != undefined) {
          this.Text4 = res.D01
        }
        if (res.D06 !== '' && res.D06 !== undefined) {
          this.Text5 = res.D06
        }
        this.inspectionDialog = true
        this.$message.success('检测成功！')
        this.endXJLoading = false
      })

    },
    //巡检结果
    inspectionOk(type) {
      let that = this
      console.log(typeof this.Text)
      console.log(this.Text.split(',') + typeof this.Text.split(','))
      if (type == 'D1') {
        that.datas = that.datas + '<div><h3>箱子在位信息</h3></div>'
        if (this.Text1 == '') {
          that.datas = that.datas + '<div>暂无数据可查看</div><hr>'
        } else {
          that.datas = that.datas + '<div>' + this.Text1 + '</div><hr>'
        }
      } else if (type == 'D2') {
        that.datas = that.datas + '<div><h3>手环在位信息</h3></div>'
        if (this.Text2 == '') {
          that.datas = that.datas + '<div>暂无数据可查看</div><hr>'
        } else {
          that.datas = that.datas + '<div>' + this.Text2 + '</div><hr>'
        }
      } else if (type == 'D3') {
        that.datas = that.datas + '<div><h3>蓝牙配对信息</h3></div>'
        if (this.Text3 == '') {
          that.datas = that.datas + '<div>暂无数据可查看</div><hr>'
        } else {
          if (this.Text3 != '所有蓝牙连接处于正常状态') {
            setTimeout(() => {
              that.hide = false
            }, 1000)
            this.equipmentNums = this.Text3.split(';')[0].split('：')[1]
            this.bluetoothNames = this.Text3.split(';')[1].split('：')[1]
            that.datas = that.datas + '<div style="display: inline-block">' + this.Text3 + '</div>'
          } else {
            that.datas = that.datas + '<div>' + this.Text3 + '</div>'
          }

          /*console.log("啊啊啊"+this.Text2.split(";")[1].split("：")[1])
          console.log("哇咔咔:"+this.Text2.split(";")[0].split("：")[1])*/
          /*let data = that.Text2.split("：")
          that.datas = that.datas+'<div>'+data[1].split(",")+'</div>'*/
          that.datas = that.datas + '<hr>'
        }
      } else if (type == 'D01') {
        that.datas = that.datas + '<div><h3>箱子设备状态信息</h3></div>'
        if (this.Text4 == '') {
          that.datas = that.datas + '<div>暂无数据可查看</div><hr>'
        } else {
          let data = this.Text4.split(',')
          let num = 0
          this.timer = setInterval(() => {
            that.datas = that.datas + '<div>' + data[num] + '</div>'
            num++

            if (num == data.length) {
              that.datas = that.datas + '<hr>'
              clearInterval(that.timer)
            }
          }, 500)
        }
      }/*else if (type == 'D06') {
        that.datas = that.datas + '<div><h3>箱子关箱记录信息</h3></div>'
        if(this.Text5==''){
          that.datas = that.datas + '<div>暂无数据可查看</div><hr>'
        }else{
          let data = this.Text5.split(',')
          let num = 0
          this.timer = setInterval(() => {
            that.datas = that.datas + '<div>' + data[num] + '</div>'
            num++

            if (num == data.length) {
              that.datas = that.datas + '<hr>'
              clearInterval(that.timer)
            }
          }, 500)
        }
      } */ else {
        that.datas = that.datas + '<div>暂无数据可查看</div>'
      }
      that.disabledInspect = true
    },
    //取消查看巡检结果
    cancelInspect() {
      if (this.timer != null) {
        clearInterval(this.timer)
      }
      this.datas = ''
      this.inspectionDialog = false
      this.hide = true
    },
    //蓝牙配对
    matchBlueTooth() {
      let that = this
      this.bluetoothLoading = true
      let params = {
        equipmentNum: this.equipmentNums,
        bluetoothName: this.bluetoothNames
      }
      postAction(this.url.bluetooth, params).then(res => {

        if (res) {
          that.$message.info('配对成功')
        } else {
          that.$message.info('配对失败')
        }
        this.bluetoothLoading = false
      })
    },
    // 添加判断方法
    isMobile() {
      this.deviceFlag = navigator.userAgent.match(
        /(phone|iPhone|ios|Android|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
      )
      if (this.deviceFlag === null) {
        this.top = '35%'
        this.rightNavShow = true
      } else {
        this.rightNavShow = false
        this.top = '0'
      }
    },

    handleOk() {
      this.Completeness = false
    },
    onChange(checkedValues) {
      console.log('checked = ', checkedValues)
    },
    info() {
      this.$info({
        title: '数据上传',
        content: this.dataContent,
        okText:"关闭",
        onOk() {
          alert(111)
        },
      });
    },
  }
}
</script>

<style scoped lang='less'>
.content {
  width: 100%;
  height: 100%;
  background-image: url("../../assets/home.jpg");
  background-size: 100% 100%;
  background-position: top center;
}

.job {

  width: 80%;
  height: 60px;
  margin: 10px
}

.sdjob {
  color: #cc0000;
  width: 80%;
  height: 60px;
  margin: 10px
}

.toolbox {
  width: 45%;
  height: 80px;
  margin: 10px;

}
.toolbox:hover,.toolbox:focus {
  width: 45%;
  height: 80px;
  margin: 10px;
  background-color: #974cd5 !important;
}
#tool_btn .ant-btn {
  background-color: #00ff80;
  color: black;
  font-size: 25px;
}

#job_btn .ant-btn {
  font-size: 25px;
  background-color: #daf6ff;
}
.whetherfont {
  font-size: 20px;
}

</style>
